//
//  BasicInfoViewController.m
//  YinHang
//
//  Created by apple on 14-9-17.
//  Copyright (c) 2014年 孙彦鹏. All rights reserved.
//

#import "BasicInfoViewController.h"
#import "getMemInfo.h"

#import "getMemInfo.h"

@interface BasicInfoViewController ()<UIScrollViewDelegate,UITextFieldDelegate,UITextViewDelegate,ASIHTTPRequestDelegate,getBasicInfo>{
    
    UIScrollView *ScrollerView;
    UIButton *rightBtn;
    UIView *numberInfoView;
    UIView *webInfoView;
    UITextFieldPadding *zhangHaoTf;
    UITextFieldPadding *webTf;
    UITextView *webTV;
    BOOL isUpdateInfo;
    NSMutableArray *basInfoMArr;
    
    getMemInfo *memInfo;//获取用户信息;
    NSMutableArray *UserArr;
    NSMutableDictionary *Infodic;//记录用户信息
    
    ASIFormDataRequest *userInfoRequest;
    
    MBProgressHUD *alterHud;
    MBProgressHUD *wait;

}

@end


@implementation BasicInfoViewController

-(void)dealloc{
    
    memInfo = nil;
    [userInfoRequest cancel];
}

#pragma mark Custom Method zhe

-(void)getdate{
    
    if (![Constants isExistenceNetwork]) {
        MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
        hud.labelText = @"没有网络";
        [hud hide:YES afterDelay:1];
        return;
    }
    if (!wait || wait.hidden == YES) {
        // 提示正在加载数据...
        wait = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
        wait.labelText = @"正在查询，请稍后...";
    }
    memInfo = [[getMemInfo alloc]init];
    memInfo.delegate = self;
    [memInfo getUserDate];
    if (memInfo != nil) {
        wait.hidden = YES;
    }
    NSLog(@"%@",memInfo.dataArr);
    
}

#pragma mark Cycle Life Method

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    Infodic = [NSMutableDictionary dictionary];
    [self getdate];//获取资料
    // Do any additional setup after loading the view from its nib.
    
    self.navigationController.navigationBarHidden = NO;
    self.navigationItem.title = @"基本资料";
    //设置返回按钮
    UIButton *leftBtn = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 20, 30)];
    [leftBtn setBackgroundImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal];
    [leftBtn addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
    
    UIBarButtonItem *leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:leftBtn];
    UIBarButtonItem *negativeSpacer = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
    negativeSpacer.width = - 10;
    if (ios7) {
        self.navigationItem.leftBarButtonItems = @[negativeSpacer,leftBarButtonItem];
    }else{
        self.navigationItem.leftBarButtonItems = @[leftBarButtonItem];
    }
    //设置修改按钮
    rightBtn = [[UIButton alloc]initWithFrame:CGRectMake(self.view.frame.size.width-40, 5, 40, 20)];
    [rightBtn setTitle:@"修改" forState:UIControlStateNormal];
    [rightBtn setTitle:@"保存" forState:UIControlStateSelected];
    [rightBtn setTintColor:[UIColor whiteColor]];
    [rightBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    UIImage *postBtn_bgImg = [UIImage imageNamed:@"postbtn_bg"];
    [rightBtn setBackgroundImage:[postBtn_bgImg stretchableImageWithLeftCapWidth:postBtn_bgImg.size.width*0.5f topCapHeight:postBtn_bgImg.size.height*0.5f] forState:UIControlStateNormal];

    [rightBtn addTarget:self action:@selector(upDateBasicInfo) forControlEvents:UIControlEventTouchUpInside];
    
    UIBarButtonItem *rightBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:rightBtn];
    self.navigationItem.rightBarButtonItem = rightBarButtonItem;
    if (ios7) {
        self.navigationItem.rightBarButtonItems = @[negativeSpacer,rightBarButtonItem];
    }else{
        self.navigationItem.rightBarButtonItems = @[rightBarButtonItem];
    }
    
    // 加载ScrollerView；
    UIScreen *screen=[UIScreen mainScreen];
    ScrollerView =[[UIScrollView alloc]initWithFrame:CGRectMake(screen.bounds.origin.x+20, 0, screen.bounds.size.width-40, screen.bounds.size.height)];
    
  
    for (UIView *v in ScrollerView.subviews) {
        [v removeFromSuperview];
    }
    
    [self.view addSubview:ScrollerView];

    [BasicInfoDataSource basicInfoDataInit];
    
    //加载ScrollerView-Contents
    [self addUpSubviews];
    [self addDownSubviews];
    
    ScrollerView.contentSize = CGSizeMake(screen.bounds.size.width-40, 1400);
    ScrollerView.pagingEnabled = NO;
    ScrollerView.directionalLockEnabled = YES;
    ScrollerView.bounces = YES;
    ScrollerView.showsHorizontalScrollIndicator = NO;
    
    ScrollerView.showsVerticalScrollIndicator = NO;
   
    ScrollerView.delegate =self;
    
    UserArr = [NSMutableArray array];
    
       
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
-(void)addUpSubviews{

    numberInfoView=[[UIView alloc]initWithFrame:CGRectMake(0, 50, ScrollerView.frame.size.width, 550)];
    numberInfoView.backgroundColor =[UIColor whiteColor];
    numberInfoView.layer.cornerRadius=5.0;
    
    UILabel *titleLbl=[[UILabel alloc]initWithFrame:CGRectMake(0, 10, 80, 40)];
        titleLbl.center=CGPointMake((self.view.frame.size.width-40)/2,30);
    titleLbl.textAlignment=NSTextAlignmentCenter;
    titleLbl.font=[UIFont boldSystemFontOfSize:18];

    titleLbl.text=@"账号信息";
    [ScrollerView addSubview:titleLbl];
    
    NSArray *labelArray=[[NSArray alloc]initWithObjects:@"账号：",@"企业名称：",@"法人姓名：",@"联系人：",@"联系地址：",@"手机：",@"座机：",@"QQ1：",@"QQ2：",@"QQ3：",nil];
 
    for (int i=0; i<10; i++) {
       
        
        UILabel *lbl=[[UILabel alloc]initWithFrame:CGRectMake(15, 30+50*i, 85, 30)];
        lbl.font=[UIFont systemFontOfSize:14];
        lbl.text=labelArray[i];
        lbl.textAlignment=NSTextAlignmentRight;
        [numberInfoView addSubview:lbl];
        
         zhangHaoTf=[[UITextFieldPadding alloc]initWithFrame:CGRectMake(95, 30+50*i, 170, 30)];
        zhangHaoTf.delegate=self;
        zhangHaoTf.userInteractionEnabled=NO;
        zhangHaoTf.tag= i + 1;
        [zhangHaoTf setPadding:YES top:0 right:5 bottom:0 left:5];
        zhangHaoTf.layer.borderColor=[UIColor lightGrayColor].CGColor;
        zhangHaoTf.layer.borderWidth=.5;
        

        zhangHaoTf.layer.cornerRadius=4.0;

        zhangHaoTf.borderStyle = UITextBorderStyleBezel;
 
        
        
        // 读取plist文件
        //NSArray *bi = [[NSArray alloc] initWithContentsOfFile:[PATH_FOR_DOCUMENT stringByAppendingPathComponent:USERFILE]];
        //NSDictionary *dic =bi[0];
        switch (i) {
            case 0:
            //{zhangHaoTf.text=[dic objectForKey:ACCOUNTNUMBER];}
            {
                zhangHaoTf.text = UNAME;
            }
                break;
            case 1:
            //{zhangHaoTf.text=[dic objectForKey:ENTERPRISENAME];}
            {
                zhangHaoTf.text = memInfo.dataArr[@"Companyname"];
            }
                break;
            case 2:
            //{zhangHaoTf.text=[dic objectForKey:BUSINESSENTITY];}
            {
                zhangHaoTf.text = memInfo.dataArr[@"Cmanfz"];
            }
                break;
            case 3:
            //{zhangHaoTf.text=[dic objectForKey:LINKMAN];}
            {
                NSString *text = [memInfo.dataArr[@"Cman"] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet ]];
                zhangHaoTf.text = text;//memInfo.dataArr[@"Cman"];
            }
                
                break;
            case 4:
            //{zhangHaoTf.text=[dic objectForKey:ADDRESS];}
            {
                //zhangHaoTf.font = [UIFont systemFontOfSize:12];
                zhangHaoTf.text = memInfo.dataArr[@"Caddr"];
            }
                break;
            case 5:
            //{zhangHaoTf.text=[dic objectForKey:PHONE];}
            {
                zhangHaoTf.text = memInfo.dataArr[@"Cmobile"];
            }
                break;
            case 6:
            //{zhangHaoTf.text=[dic objectForKey:TEL];}
            {
                zhangHaoTf.text = memInfo.dataArr[@"Ctel"];
            }
                break;
            case 7:
            //{zhangHaoTf.text=[dic objectForKey:QQ1];}
            {
                zhangHaoTf.text = memInfo.dataArr[@"Cfax"];
            }
                break;
            case 8:
            //{zhangHaoTf.text=[dic objectForKey:QQ2];}
            {
                zhangHaoTf.text = memInfo.dataArr[@"Cfax2"];
            }
                break;
            case 9:
            //{zhangHaoTf.text=[dic objectForKey:QQ3];}
            {
                zhangHaoTf.text = memInfo.dataArr[@"Cfax3"];
            }
                break;
           
            default:
                break;
        }
        [numberInfoView addSubview:zhangHaoTf];
        
    }
    
    [ScrollerView addSubview:numberInfoView];




}

-(void)addDownSubviews{

    webInfoView=[[UIView alloc]initWithFrame:CGRectMake(0, 670, ScrollerView.frame.size.width, 900)];
    webInfoView.backgroundColor =[UIColor whiteColor];
    webInfoView.layer.cornerRadius=5.0;
    
    UILabel *titleLbl=[[UILabel alloc]initWithFrame:CGRectMake(0, 10, 80, 40)];
    titleLbl.center=CGPointMake((self.view.frame.size.width-40)/2,650);
    titleLbl.textAlignment=NSTextAlignmentCenter;
    titleLbl.font=[UIFont boldSystemFontOfSize:18];
    
    titleLbl.text=@"网站信息";
    [ScrollerView addSubview:titleLbl];
    
    NSArray *labelArray=[[NSArray alloc]initWithObjects:@"网站名称：",@"网站LOGO：",@"网站简介：",@"LOGO链接：",@"状态：",nil];
    
    
    // 读取plist文件
    NSArray *bi = [[NSArray alloc] initWithContentsOfFile:[PATH_FOR_DOCUMENT stringByAppendingPathComponent:USERFILE]];
    NSDictionary *dic =bi[0];
    
    for (int i=0; i<5; i++) {
        UILabel *lbl=[[UILabel alloc]init];
        lbl.font=[UIFont systemFontOfSize:14];
        lbl.text=labelArray[i];
        lbl.textAlignment=NSTextAlignmentRight;
        webTf=[[ UITextFieldPadding alloc]init];
        webTf.delegate=self;
        webTf.userInteractionEnabled=NO;
        [webTf setPadding:YES top:0 right:5 bottom:0 left:5];
        webTf.layer.borderColor=[UIColor lightGrayColor].CGColor;
        webTf.layer.borderWidth=.5;
        webTf.borderStyle = UITextBorderStyleBezel;
        


        
        switch (i) {
            case 0:
            {
                //网站名称
                lbl.frame=CGRectMake(15, 30, 85, 30);
                 webTf.frame= CGRectMake(100, 30, 170, 30);
                webTf.tag=11;
                //webTf.text=[dic objectForKey:WEBNAME];
                webTf.text = memInfo.dataArr[@"Cname"];
               [webInfoView addSubview:webTf];
            }
                break;
            case 1:
            {
                //网站LOGO
                lbl.frame=CGRectMake(15, 80, 85, 30);
                
                UIImageView *iv=[[UIImageView alloc]initWithFrame:CGRectMake(110, 80, 80, 80)];
                iv.backgroundColor=[UIColor brownColor];
                iv.tag=12;
                
                iv.image=[UIImage imageNamed:[dic objectForKey:WEBLOGO]];
                [iv setImageURL:memInfo.dataArr[@"Picture"] placeholder:PLACE_HODER_IMG];
                iv.contentMode = UIViewContentModeScaleAspectFit;
                [webInfoView addSubview:iv];
            }
                break;
            case 2:
            {
                //网站简介
                lbl.frame=CGRectMake(15, 180, 85, 30);
                webTV=[[UITextView alloc]initWithFrame:CGRectMake(100, 180, 170, 350)];
                webTV.delegate=self;
                webTV.scrollEnabled = YES;
               
                webTV.userInteractionEnabled=YES;
                 //[webTV.layer setCornerRadius:3.0];
                webTV.layer.borderColor=[UIColor grayColor].CGColor;
                webTV.layer.borderWidth=1;
                
                
                //[webTV sizeToFit];
                webTV.tag=13;
               // webTV.text=[dic objectForKey:WEBINTRO];
                NSLog(@"%@",memInfo.dataArr[@"Content"]);
                webTV.text = [NSString stringWithFormat:@"%@",memInfo.dataArr[@"Content"]];
                 //webTV.autoresizingMask = UIViewAutoresizingFlexibleHeight;
                webTV.autoresizingMask = UIViewAutoresizingFlexibleHeight;
                CGFloat height;
                if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7) {
                    
                    CGRect textFrame=[[webTV layoutManager]usedRectForTextContainer:[webTV textContainer]];
                    height = textFrame.size.height;
                    
                }else {
                    
                    height = webTV.contentSize.height;
                }
                webTV.frame = CGRectMake(100, 180, 170, height);
                [webInfoView addSubview:webTV];

            }
                break;
            case 3:
            {
                //logo链接
                lbl.frame=CGRectMake(15, 540, 85, 30);
                webTf.frame= CGRectMake(100, 540, 170, 30);
                webTf.tag=14;
                //webTf.text=[dic objectForKey:WEBLINK];
                webTf.text = memInfo.dataArr[@"Cweb"];
                [webInfoView addSubview:webTf];

            }
                break;
            case 4:
            {
                //状态
                lbl.frame=CGRectMake(15, 590, 85, 30);
                webTf.frame= CGRectMake(100, 590, 170, 30);
                webTf.tag=15;
                //webTf.text=[dic objectForKey:STATUS];
                if ([memInfo.dataArr[@"Isok"] isEqualToString:@"1"]) {
                    webTf.text = @"审核通过";
                    
                }else{
                    webTf.text = @"已屏蔽";
                }
                [webInfoView addSubview:webTf];

            }
                break;
          
            default:
                break;
        }
        
        
        [webInfoView addSubview:lbl];
    }
    
    
    
    [ScrollerView addSubview:webInfoView];


}

// 返回
- (void)back {
       
    [self.navigationController popViewControllerAnimated:YES];
}
//修改基本资料

-(void)upDateBasicInfo{
    rightBtn.selected =!rightBtn.selected;
    if (!isUpdateInfo) {
          for (int j=1; j<11; j++) {
        UITextFieldPadding *tf=(UITextFieldPadding *)[numberInfoView viewWithTag:j];
        tf.userInteractionEnabled=YES;
    }
    for (int j=11; j<15; j++) {
        if (j==12) {
            UIImageView *iv=(UIImageView *)[webInfoView viewWithTag:j];
            iv.userInteractionEnabled=YES;
        }
        if (j==13) {
            UITextView *tv=(UITextView *)[webInfoView viewWithTag:j];
            tv.userInteractionEnabled=YES;
        }
        else{
            UITextFieldPadding *tf=(UITextFieldPadding *)[webInfoView viewWithTag:j];
            tf.userInteractionEnabled=YES;
        }
    }
        isUpdateInfo=YES;
    }
    else{
        // 将人物模型转化为字典
        //NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
        for (int j=1; j<15; j++) {
            if (j<11) {
                UITextFieldPadding *tf=(UITextFieldPadding *)[numberInfoView viewWithTag:j];
               
                switch (j) {
                    case 1:
                    {//[dic setObject:tf.text forKey:ACCOUNTNUMBER];
                    //记录
                    }
                        break;
                    case 2:
                    {//[dic setObject:tf.text forKey:ENTERPRISENAME];
                        [Infodic setObject:[NSString stringWithFormat:@"%@",tf.text] forKey:@"companyname"];
                    }
                        break;
                    case 3:
                    {//[dic setObject:tf.text forKey:BUSINESSENTITY];
                        [Infodic setObject:[NSString stringWithFormat:@"%@",tf.text] forKey:@"cmanfz"];
                    }
                        break;
                    case 4:
                    {//[dic setObject:tf.text forKey:LINKMAN];
                        [Infodic setObject:[NSString stringWithFormat:@"%@",tf.text] forKey:@"cman"];
                    }
                        break;
                    case 5:
                    {//[dic setObject:tf.text forKey:ADDRESS];
                    [Infodic setObject:[NSString stringWithFormat:@"%@",tf.text] forKey:@"caddr"];
                    }
                        break;
                    case 6:
                    {//[dic setObject:tf.text forKey:PHONE];
                    [Infodic setObject:[NSString stringWithFormat:@"%@",tf.text] forKey:@"cmobile"];
                    }
                        break;
                    case 7:
                    {//[dic setObject:tf.text forKey:TEL];
                        [Infodic setObject:[NSString stringWithFormat:@"%@",tf.text] forKey:@"ctel"];
                    }
                        break;
                    case 8:
                    {//[dic setObject:tf.text forKey:QQ1];
                        [Infodic setObject:[NSString stringWithFormat:@"%@",tf.text] forKey:@"cfax"];
                    }
                        break;
                    case 9:
                    {//[dic setObject:tf.text forKey:QQ2];
                        [Infodic setObject:[NSString stringWithFormat:@"%@",tf.text] forKey:@"cfax2"];
                    }
                        break;
                    case 10:
                    {//[dic setObject:tf.text forKey:QQ3];
                        [Infodic setObject:[NSString stringWithFormat:@"%@",tf.text] forKey:@"cfax3"];
                    }
                        break;
                        
                    default:
                        break;
                }
 
                
                
            }else if (j==12){
            
               
//                UIImageView *iv=(UIImageView *)[webInfoView viewWithTag:j];
//               [dic setObject:@"string" forKey:WEBLOGO];
            }
            
            
            else if  (j==13) {
                 UITextView *tv=(UITextView *)[webInfoView viewWithTag:j];
                //[dic setObject:tv.text forKey:WEBINTRO];
                [Infodic setObject:[NSString stringWithFormat:@"%@",tv.text] forKey:@"content"];
            }else{
            
                UITextFieldPadding *tf=(UITextFieldPadding *)[webInfoView viewWithTag:j];
                switch (j) {
                    case 11:{
                        //[dic setObject:tf.text forKey:WEBNAME];
                        [Infodic setObject:[NSString stringWithFormat:@"%@",tf.text] forKey:@"cname"];
                    
                    }
                        break;
                    case 14:
                        //[dic setObject:tf.text forKey:WEBLINK];
                        break;
                    case 15:
                      // [dic setObject:tf.text forKey:STATUS];
                        break;
                    default:
                        break;
                }
            
            }
        }
        
        //提交修改
        if (![Constants isExistenceNetwork]) {
            
        } else {
            alterHud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
            alterHud.labelText = @"正在修改，请稍后...";
            userInfoRequest = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:API_STR]];
            userInfoRequest.requestMethod = @"POST";
            // 设置超时时间
            userInfoRequest.timeOutSeconds = 30;
            userInfoRequest.delegate = self;
            // 设置参数
            NSString *action = @"update";
            NSDictionary *paramsDict = [NSDictionary dictionary];
            paramsDict =  @{@"uid": UNAME,
                            @"companyname":Infodic[@"companyname"]                                         ,
                            @"cname":Infodic[@"cname"],
                            @"cmanfz":Infodic[@"cmanfz"],
                            @"cman":Infodic[@"cman"],
                            @"ctel":Infodic[@"ctel"],
                            @"cmobile":Infodic[@"cmobile"],
                            @"caddr":Infodic[@"caddr"],
                            @"content":Infodic[@"content"],
                            @"cfax":Infodic[@"cfax"],
                            @"cfax2":Infodic[@"cfax2"],
                            @"cfax3":Infodic[@"cfax3"]
                            };
            
            NSString *paramsStr = [NSString JSONString:paramsDict];
            
            NSString *result = [NSString stringWithFormat:TEMPLATE_PARAMSTR, action,paramsStr];
            
            NSData *paramsData = [result toGBKEncodingData];
            userInfoRequest.postBody = [paramsData mutableCopy];
            
            [userInfoRequest startAsynchronous];
        }

        
        isUpdateInfo=NO;
        // 读取plist文件
        //NSMutableArray *bi = [[NSMutableArray alloc] initWithContentsOfFile:[PATH_FOR_DOCUMENT stringByAppendingPathComponent:USERFILE]];
        //NSMusicDirectory *dic =bi[0];
        //[bi removeAllObjects];

        //[bi addObject:dic];
        // 字典写成plist文件
       // NSString *filePath = [PATH_FOR_DOCUMENT stringByAppendingPathComponent:USERFILE];
//        if ( [bi writeToFile:filePath atomically:YES]){
//        
//            [self.navigationController popViewControllerAnimated:YES];
//        }
    }

}


-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
  
    for (int j=1; j<11; j++) {
        UITextFieldPadding *tf=(UITextFieldPadding *)[numberInfoView viewWithTag:j];
        [tf resignFirstResponder];
    }
    
    for (int j=11; j<15; j++) {
        
        if (j==12) {
            UITextView *tv=(UITextView *)[webInfoView viewWithTag:j];
            [tv resignFirstResponder];
        }
        else{
        UITextFieldPadding *tf=(UITextFieldPadding *)[webInfoView viewWithTag:j];
            [tf resignFirstResponder];}
    }

    
    
}
-(void)textFieldDidBeginEditing:(UITextField *)textField{





}

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
    
    
    
    return YES;
}

-(BOOL)textFieldShouldReturn:(UITextField *)textField{
    UITextFieldPadding *tf;
    if (textField.tag<10) {
         tf=(UITextFieldPadding *)[numberInfoView viewWithTag:textField.tag+1];
  
   
    }
   
    else if (textField.tag==10){
        tf=(UITextFieldPadding *)[webInfoView viewWithTag:11];

    
    
    }else if (textField.tag<14){
    
        if (textField.tag==11) {
            [webTV becomeFirstResponder];
            return YES;
        }
        
        tf=(UITextFieldPadding *)[webInfoView viewWithTag:textField.tag+1];

    
    
    }else{
    
        [textField resignFirstResponder];
        return YES;
    }
    
    [tf becomeFirstResponder];
    return YES;
}


-(void)textViewDidBeginEditing:(UITextView *)textView{
   

    
     [ScrollerView setContentOffset:CGPointMake(0, 710)];

    
}

- (void)textViewDidEndEditing:(UITextView *)textView

{
    
   
}

#pragma mark - ASIHttpRequestDelegate method

- (void)requestFinished:(ASIHTTPRequest *)request {
    alterHud.hidden = YES;
    NSLog(@"%@",request.responseString);
    NSError *err;
    NSDictionary *result = [NSJSONSerialization JSONObjectWithData:[request.responseString dataForUTF8] options:NSJSONReadingAllowFragments error:&err];
    
    // 1. 是否解析有错误
    if (!err) {
        
        // 2. 判断错误码
        NSInteger errorCode = [result[@"errorCode"]integerValue];
        if (errorCode == 0) {
            [alterHud hide:YES];
            sleep(2);
            [SVProgressHUD showSuccessWithStatus:@"修改成功"];
            
            
            //[self.navigationController popViewControllerAnimated:YES];
            
            
        } else {
            [alterHud hide:YES];
            [SVProgressHUD showErrorWithStatus:result[@"errorMsg"]];
        }
        
    } else {
        [alterHud hide:YES];
        [SVProgressHUD showErrorWithStatus:@"数据解析出错！"];
    }
}

- (void)requestFailed:(ASIHTTPRequest *)request {
    [alterHud hide:YES];
    [SVProgressHUD showErrorWithStatus:@"服务器无法访问，请稍后再试!"];
}
-(void)receiveData{
    [self addUpSubviews];
    [self addDownSubviews];
}

@end
